package com.liy.framework.web.rs.resource;

import com.liy.framework.common.dao.IBaseDao;
import com.liy.framework.common.extvo.ResultVO;
import com.liy.framework.common.vo.BaseVO;
import com.liy.framework.common.vo.PageVO;
import com.liy.framework.web.rs.service.SupportResource;
import java.util.List;
import javax.ws.rs.BeanParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@Produces({"application/json;charset=UTF-8"})
public class QueryResource<Entity extends BaseVO<String>, BaseDao extends IBaseDao<Entity, String>> extends SupportResource implements IQueryResource<Entity> {

    protected static Logger log = LoggerFactory.getLogger(QueryResource.class);

    @Autowired
    protected BaseDao baseDao;



    @GET
    @Path("get/{id}")
    public Response findById(@PathParam("id") String id) throws Exception {
        ResultVO resultVO = new ResultVO(true, "查询成功.");
        resultVO.setData(this.baseDao.selectByPrimaryKey(id));
        return Response.ok(resultVO).build();
    }

    @GET
    @Path("/list")
    public Response findList(@BeanParam Entity entity) throws Exception {
        List<Entity> list = this.baseDao.selectList(entity);
        ResultVO resultVO = new ResultVO(true, "查询成功.");
        resultVO.setData(list);
        return Response.ok(resultVO).build();
    }

    @GET
    @Path("/query/{pageSize}/{pageNo}")
    public Response findByPage(@BeanParam Entity entity, @PathParam("pageSize") Integer pageSize, @PathParam("pageNo") Integer pageNo) throws Exception {
        PageVO<Entity> pageVO = new PageVO(pageNo, pageSize);
        this.baseDao.selectByPage(entity, pageVO);
        return Response.ok(pageVO).build();
    }
}
